#coding:utf-8
from liblcd import Screen
from datetime import *
from libTextToSpeech import TextToSpeech
from libbase import TickCenter
from libbase import EventCenter
import events
from libbluetooth import BlueToothDaemon
import time

BT_MAC_XIAODU = "CC:E0:DA:94:2F:AE"
isSayed = False

def _onBlueTooth(mac):
    if mac == BT_MAC_XIAODU:
        time.sleep(10)
        if BlueToothDaemon().isDeviceConnected(BT_MAC_XIAODU):
            TextToSpeech().setEnglish(False)
            TextToSpeech().say("连接成功，你好，我是机器人。")


if __name__ == "__main__":
    try:
        screen = Screen(addr=0x27)
        screen.clear()
        screen.enable_backlight()
        screen.display_data("Hello LEO!", "TIME -> " + datetime.now().strftime("%H:%M:%S"))
    except:
        pass
    EventCenter().subscribe(events.EVENT_BLUETOOTH_CONNECT, None, _onBlueTooth)
    BlueToothDaemon().addDevice(BT_MAC_XIAODU)          #小度音箱
    TextToSpeech().setWordPerMinute(150)

    # TextToSpeech().setEnglish(False)
    # TextToSpeech().say("刘炼，我要把你打成巴巴屁")


    #enter main loop
    while True:
        time.sleep(0.1)
        TickCenter().tick(0.1)